<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>socket-demo</title>
</head>

<body>
  <button id="btn-send">发送</button>
</body>
<script src="http://lib.baomitu.com/socket.io/3.1.2/socket.io.js"></script>
<script>
  const info = {}
  const search = window.location.search.replace('?', '');
  search.split('&').forEach(el => {
    const i = el.split('=');
    info[i[0]] = i[1];
  });

  const socket = io.connect('http://localhost:3000');

  socket.on('connect', function () {
    console.info('connect')
    socket.emit('online', info.user);
    socket.on('disconnect', () => {
      console.log('disconnect')
    })
  });

  socket.on('news', function (params) {
    console.info(params)
  });

  // document.querySelector('#btn-send').addEventListener('click', () => {
  //   socket.emit('news', {
  //     receiver: info.receiver,
  //     content: 'hello from ' + info.user
  //   })
  // })
</script>
</html>